package com.barbarosso.utils.loader {
	import com.barbarosso.utils.array.ArrayCollection;
	import com.barbarosso.utils.loader.types.AbstractAsset;		

	/**
	 * @author barbarosso
	 */
	public class AssetCollection extends ArrayCollection {
		
                private var _id			:String; //  id
                private var _totalKb 	: int;
                private var _loadedKb 	: int;

		/**
                 * Constructor 
                 */
                public function AssetCollection(p_id : String ) : void {
                        super();
                        _id = p_id;
                }
                
                /**
                 * toString
                 */
                override public function toString(): String {
                        return id + ': ' + length;
                }
                
                /**
                 * getAsset
                 */
                public function getAsset(id:String) : AbstractAsset {
                        return getItemByChildProperty('id',id) as AbstractAsset;
                }
                
                /**
                 * Adds an item to the end of the array
                 */
               public function addAsset(item:Object) : Boolean
                {
                	var asset : AbstractAsset = item as AbstractAsset; 
					if(isAddAllowed(asset))
					{
                        	_data.push(item);
                        	return true;
                     }
                     return false;
                }
                
                protected function isAddAllowed( item : AbstractAsset) : Boolean{
                	var loops:int = data.length; // optimizes for-loop.
                        for(var i:int; i < loops; i++)
                        {
							if(AbstractAsset(_data[i]).id == item.id)
                            {
                                    return false;
                            }
                        }
                	return true;
                }

				/**
                 * Read only property
                 */
                public function get id():String {
						return _id;
				}
		
	}
}
